<template>
  <ul class="right-list-container">
    <h2>{{ title }}</h2>
    <li v-for="(item, i) in list" :key="i">
      <span @click="handleClick(item)" :class="{ active: item.isSelect }">
        {{ item.name }}
      </span>
      <span v-if="item.aside" @click="handleClick(item)" class="aside" :class="{ active: item.isSelect }">
        {{ item.aside }}
      </span>
      <!-- 显示当前组件 -->
      <RightList :list="item.children" @select="handleClick(item)" />
    </li>
  </ul>
</template>

<script setup lang="ts">
const $emit = defineEmits(['select'])
type propsType = {
  list: any[]
  title?: string
}
withDefaults(defineProps<propsType>(), {
  list: () => []
})
function handleClick(item: any) {
  $emit('select', item)
}
</script>

<style lang="scss" scoped>
@import '@/styles/var.scss';
.right-list-container {
  list-style: none;
  padding: 0;
  h2 {
    font-weight: bold;
    letter-spacing: 2px;
    font-size: 1em;
    margin: 0;
  }
  .right-list-container {
    margin-left: 1em;
  }
  li {
    min-height: 40px;
    line-height: 40px;
    font-size: 14px;
    cursor: pointer;
    .active {
      color: $warn;
      font-weight: bold;
    }
  }
}
.aside {
  font-size: 12px;
  margin-left: 1em;
  color: $gray;
}
</style>
